#include <stdlib.h>
#include <stdio.h>
#include "clientList.h"

struct clientInfo* createList()
{
    struct clientInfo* head = (struct clientInfo*)malloc(sizeof(struct clientInfo));
    head->next = NULL;
    if(head == NULL)
    {
        return NULL;
    }
    return head;
}

struct clientInfo* pushFront(struct clientInfo* head,int fd)
{
    struct clientInfo* newNode = (struct clientInfo*)malloc(sizeof(struct clientInfo));
    newNode->fd = fd;
    newNode->next = head->next;
    head->next = newNode;
    return newNode; 
}

bool eraseNode(struct clientInfo* head,int fd)
{
    struct clientInfo* pos = head;
    struct clientInfo* next = head->next;
    while(next)
    {
        if(next->fd == fd)
        {
            pos->next = next->next;
            free(next);
            printf("删除节点成功，fd为 %d ",fd);
            return true;
        }
        pos = pos->next;
        next = next->next;
    }
    return false;
}

void freeList(struct clientInfo* head)
{
    struct clientInfo* pos = head;
    while(pos)
    {
        struct clientInfo* tmp = pos;
        pos = pos->next;
        free(tmp);
    }
}